package com.matt.controller.web;

import com.matt.domain.TeachingArea;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import com.matt.foundation.vo.TeachingAreaPageVo;
import com.matt.foundation.vo.TeachingAreaVo;
import com.matt.service.TeachingAreaService;

import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/9/4
 * *******************************
 */
@RestController
@RequestMapping("/web/teaching_area")
public class WebTeachingAreaController {

    @Autowired
    private TeachingAreaService teachingAreaService;

    @Autowired
    private MemVerificationCache cache;

    @ApiOperation(value = "创建教学园区",httpMethod = "POST")
    @RequestMapping(value = "/create")
    public StatusResponse create(@RequestHeader String ticket, String name, String remark, String[] cameraIds, Boolean isPublic) {
        String areaId = cache.getAreaId(ticket);
        TeachingArea teachingArea = teachingAreaService.addTeachingArea(name, remark, cameraIds, areaId, isPublic);
        return StatusResponse.success(teachingArea);
    }

    @ApiOperation(value = "获取教学园区",httpMethod = "POST")
    @RequestMapping(value = "/page_by_area")
    public StatusResponse listByArea(@RequestHeader String ticket, Boolean publicFilter, PagerQuery query) {
        String areaId = cache.getAreaId(ticket);
        Page<TeachingAreaPageVo> teachingArea = teachingAreaService.pageTeachingAreaByArea(areaId,publicFilter, query);
        return StatusResponse.success(teachingArea);
    }

    @ApiOperation(value = "教学园区详情",httpMethod = "POST")
    @RequestMapping(value = "/detail")
    public StatusResponse detail(@RequestHeader String ticket, String teachingAreaId) {
        String areaId = cache.getAreaId(ticket);
        TeachingAreaVo teachingArea = teachingAreaService.getTeachingAreaById(teachingAreaId, areaId);
        return StatusResponse.success(teachingArea);
    }

    @ApiOperation(value = "修改教学区域",httpMethod = "POST")
    @RequestMapping(value = "/modify")
    public StatusResponse detail(@RequestHeader String ticket, String teachingAreaId, String name, String remark, String[] cameraIds, Boolean isPublic) {
        String areaId = cache.getAreaId(ticket);
        TeachingArea teachingArea = teachingAreaService.modify(teachingAreaId, name, remark, cameraIds, areaId, isPublic);
        return StatusResponse.success(teachingArea);
    }
}
